In this lecture, we'll explore the implementation
of our sound effects in our feed the teddies game. As you can see, we have six different cues that we're going to play
as part of the game. We have a BurgerDamageCue, a BurgerDeathCue,
a BurgerShotCue, a button click for
our menu buttons, a TeddyDeathCue,
and a TeddyShotCue. We'll go and look
at the cues that are played by the burger and the teddy bears
first and then we'll take a look at how we do
button clicks in our menus. In our BurgerPawn, when we take damage
from a teddy bear, we play our 2D sound
in the usual way. We learned this way back
when we learned how to play sound effect and we're
playing our BurgerDamageCue, which I have set
as a property that I've populated in the
blueprint editor. I play that same sound when I take damage from a
teddy bear projectile, when I shoot French fries, I play the BurgerShotCue, and when I discovered
that the game is over because I've
run out of health, I play the BurgerDeathCue. Here in the BurgerPawn
header file, here's where I have
those U properties for populating the BurgerDamageCue, BurgerDeathCue, and BurgerShotCue in
the blueprints editor. My teddy bear actor plays
two different cues, the TeddyShotCue when it shoots a teddy bear projectile and the TeddyDeathCue when
the teddy bear dies. I have these U
properties here so I can populate those in
the blueprints editor. Then in the implementation file, when I die because I have a collision with a
burger or French fries, I played the TeddyDeathCue
and I will say, I did some refactoring
when I talked about basic gameplay and collisions between fries and teddy bears, I just destroyed
the teddy bear over there in the French fries
and I refactored a little bit so that I could
have the teddy bear play its own death
sound on that overlap. I changed how collisions
between French fries and teddy bears work compared to what I showed you previously. Now, the way it works is if French fries collide
with a teddy bear actor, the French fries destroy
themselves and broadcast the add points event but they don't destroy
the teddy bear, the teddy bear
detects that overlap here so it can play
its own sound effect. We certainly could have played the TeddyDeathCue over
in the French fries, but that's not good
object-oriented design. We should have the teddy
bear play its own death cue. The other cue that
the teddy bear plays is when it shoots
a teddy bear projectile, it plays the TeddyShotCue. Those are the five sound effects that are played from
within C++ code. Let's go take a look
at the menu buttons. We'll just look at
the playing the sound for the buttons in the
main menu because it works exactly the same way for every menu button
in my menu system. We'll look at the
event graph and you'll see that for each of
the menu buttons, I've responded to the on pressed event and on pressed for each of
these menu buttons, I just play the 2D sound,
the ButtonClickCue. You might think it would
have been easier to just go to the on clicked events for all the menu buttons and
play this sound here. I will confess
that I tried that, but I couldn't get it to work. It would never play the
sound on a button click. I play the sound when the
player presses the button, and then I do the
full click processing in response to the
on clicked event, which is, of course, the player pressing and then
releasing the button. I also could have
played the sound on released instead
of on pressed, but it felt more responsive to the player to actually
play the sound on pressed. That's how I got all of my menu buttons to play
the button click sound. For each of the menu
buttons in my menus, I add a response to
the on pressed event, and I play the ButtonClickCue. To recap, in this lecture, we explored how to include both gameplay and menu button
sound effects in our game.